<%--
   uploader Selector
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@tag import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@ tag language="java" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%@ attribute name="id" required="true" type="java.lang.String"
	description="唯一标识。"%>
<%@ attribute name="sourceId" required="true" rtexprvalue="true"
	type="java.lang.String" description="关联实体的唯一标识。"%>
<%@ attribute name="sourceType" required="false" rtexprvalue="true"
	type="java.lang.String" description="存储的表名，不填则为app_upload_file"%>
<%@ attribute name="forCustomer" required="false" rtexprvalue="true"
	type="java.lang.Boolean" description="是否客户上传。"%>
<%@ attribute name="readonly" required="false" rtexprvalue="true"
	type="java.lang.Boolean" description="是否为只读。"%>
<%@ attribute name="hidetips" required="false" rtexprvalue="true"
	type="java.lang.Boolean" description="是否为显示提示文字。"%>
<c:set var="readonly" value="${empty readonly?false:readonly }" />
<c:if test="${readonly eq false}">
	<a class="nui-txt-link" onclick=" ${id}.openUploaderDialog();"><span
		class="icon icon-plus"></span>上传文件</a>
	<c:if test="${hidetips eq false}">
		<br>支持格式：<%=ContextHolder.getUploadFileTypes()%>&nbsp;大小：<%=ContextHolder.getUploadFileMaxSize()%>
	</c:if>
</c:if>
<div id="${id}Files" style="clear:both"></div>
<div id="${id}Dialog" title="上传文件" style="height:360px;display: none">
	<div id="${id}" class="box"></div>
	<p class="info-txt">
		支持格式：<%=ContextHolder.getUploadFileTypes()%>&nbsp;大小：<%=ContextHolder.getUploadFileMaxSize()%></p>
</div>
<div id="${id}FileInfo" title="文件详细" style="display:none">
	<table class="form-table" style="line-height: 23px;">
		<tr>
			<td class="td1">文件名：</td>
			<td><a style="text-decoration: underline;color:blue"
				id="${id}FileInfoName" href="" target="_blank"></a></td>
		</tr>
		<tr>
			<td class="td1">存储位置：</td>
			<td class="td2"><label id="${id}FileInfoPath"></label></td>
		</tr>
		<tr>
			<td class="td1">大小：</td>
			<td class="td2"><label id="${id}FileInfoSize"></label>KB</td>
		</tr>
		<tr>
			<td class="td1">上传者：</td>
			<td class="td2"><label id="${id}FileInfoModifier"></label></td>
		</tr>
		<tr>
			<td class="td1">上传时间：</td>
			<td class="td2"><label id="${id}FileInfoModifyDate"></label></td>
		</tr>
	</table>
</div>
<div style="clear:both;height:1px"></div>
<div id="showImg" class="hide" style="display: none;"><img src="uploadFile/201807/296711427630780024.jpg" heigth="600" width="600"></div>
<script type="text/javascript">
	var ${id}=$("#${id}").uploader({readonly:${readonly},sourceId:"${sourceId}",sourceType:"${sourceType}",maxSize:"<%=ContextHolder.getUploadFileMaxSize()%>",fileTypes:"<%=ContextHolder.getUploadFileTypes()%>",uploadUrl:"<%=request.getContextPath()%>/fileUpload",downloadUrl:'<%=request.getContextPath()%>/fileDownload'});
</script>
<script src="js/libs/layer/layer.js"></script>
<script type="text/javascript">

function bytesToSize(bytes) {
    if (bytes === 0) return '0 B';
    var k = 1000, // or 1024
        sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
        i = Math.floor(Math.log(bytes) / Math.log(k));
   return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}
function areImgFile(extName)
{
  var imgf="png/jpg/jpeg/bmp/gif";
  if(imgf.indexOf(extName)>-1)
  {
    return true;
  }else
  {
    return false;
  }
}
function showImg(src)
{ 
   $("#showImg").src=src;
   layer.open({
      type: 1,
      title: false,
      closeBtn: 0,
      area: '600px',
      skin: 'layui-layer-nobg',
      shadeClose: true,
      content: $('#showImg')
});
}
</script>
